package gaml.text.printer;

import gaml.core.GamlConfig;
import gaml.error.GamlException;
import gaml.text.TextNodeBridge;
import gaml.text.YamlLine;
import gaml.text.YamlNodePrinter;
import gaml.text.YamlPrinterStore;
import gaml.text.YamlText;
import gaml.yaml.SequenceNode;
import gaml.yaml.YamlNode;


/**
 * make text from list yaml node
 * @author shnireck
 *
 */
public class SequenceNodePrinter implements YamlNodePrinter <SequenceNode> {
	YamlPrinterStore store = null;
	GamlConfig config = null;
	
	public SequenceNodePrinter (YamlPrinterStore store, GamlConfig config) {
		this.store = store;
		this.config = config;
	}

	@Override
	public Class <SequenceNode> getPrintNodeClass () { return SequenceNode.class; }

	@Override
	public SequenceNodePrinter print (SequenceNode node, YamlText text) throws GamlException {
		text.addLine (
				new YamlLine ()
					.setTag (node.getTag ())
					.setAnchor (null == node.getAnchor () ? "" : node.getAnchor ().getCode ())
					.setValue ("[")
					.setIdent (node.getLevel ()));
		
		for (YamlNode child: node.getSequenceChildren ()) {
			text.addLine (new YamlLine ().setValue ("-").setIdent (node.getLevel () + 1));
			text.appendText (new TextNodeBridge (new YamlText (config, child.getLevel ()), child).parseNode (store).getText ());
		}
		text.addLine (new YamlLine ().setValue ("]").setIdent (node.getLevel ()));

		return this;
	}

}
